<template>
  <div class='my-fixed'>
    <div class='parent'>
      <div class="m-no-select cursor_default m-no-select cursor_default"
           style='border:1px solid #e5e5e5;display: flex;justify-content: space-between;line-height: 36px;height:36px;padding: 0 20px;align-items: center;'>
        <h3 style='display: inline-block;'>系统设置</h3>
        <img src="static/image/home/closeWindow.png" style='width: 14px;height: 14px;cursor:pointer;' @click='close' />
      </div>
      <div class="system_wrap">
        <div class="system_left">
          <ul>
            <li v-for="(item, index) in menuList" :key="'menu' + index" @click="changeMenu(index)"
                :class="{ active: activeIndex == index }">{{ item }}</li>
          </ul>
        </div>
        <div style="flex:1;height:100%;">
          <!-- zk126修改theight: calc(100% - 36px) -->
          <div style='width: 100%;height: calc(100% - 36px);overflow:auto;position:relative;'>
            <div class="promptSetting m-no-select cursor_default" v-show="activeIndex == 0">
              <div>
                <div>接收新消息通知</div>
                <i-switch v-model="newMessage" @click.native='messageClick'></i-switch>
              </div>
              <div>
                <div>消息提示音</div>
                <i-switch v-model="voicePrompt" @click.native='voiceClick'></i-switch>
              </div>
              <div>
                <div>桌面通知</div>
                <i-switch v-model="deskNotic" @click.native='noticClick'></i-switch>
              </div>
              <div>
                <div>开机启动</div>
                <i-switch v-model="bootlogin" @click.native='bootloginChange'></i-switch>
              </div>
              <div>
                <div>关闭窗口最小化到托盘</div>
                <i-switch v-model="minimized" @click.native='minimizedClick'></i-switch>
              </div>
            </div>
            <div class="shortcuts" v-show="activeIndex == 1">
              <div>
                <div>搜索</div>
                <Input v-model='search' @keydown.native="searchKeydown" @on-blur="searchUp" />
              </div>
              <div>
                <div>截图</div>
                <Input v-model='screen' @keydown.native="screenKeydown" @on-blur="screenUp" />
              </div>
              <div>
                <div>跳转未读会话</div>
                <Input v-model='session' @keydown.native="sessionKeydown" @on-blur="sessionUp" />
              </div>
              <div>
                <div>激活窗口</div>
                <Input v-model='activation' @keydown.native="activationKeydown" @on-blur="activationUp" />
              </div>
              <div>
                <div>发送消息</div>
                <div>
                  <select name="" id="" @change='sendSet' v-model='send'
                          style='width: 100%;border-radius:4px;height:32px;border:1px solid #dddee1;cursor:pointer;'>
                    <option :value="1">enter发送，ctrl+enter换行</option>
                    <option :value="0">ctrl+enter发送，enter换行</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="file_manage" v-show="activeIndex == 2">
              <div class="catalog_manage">
                <div class="c_m_t">
                  <div>文件管理:</div>
                  <div>默认把接收到的文件保存到此文件夹中:</div>
                </div>
                <div class="c_m_i"><input type="text" readonly="true" v-model="pathValue" /></div>
                <div class="c_m_b">
                  <button @click='editPath'>更改目录</button>
                  <button @click='openPathByUrl'>打开文件夹</button>
                </div>
              </div>
            </div>
            <div v-show="activeIndex == 3">
              <div class="my_status_set">
                <div class="my_status_item">
                  <div>状态</div>
                  <div class="my_status_main">
                    <div>
                      <input style="height:20px;width:20px;margin-right:5px;" type="checkbox" @change="statusChange"
                             v-model="isLeave">窗口无动作后
                    </div>
                    <div>
                      <input type="number" @blur="leaveTimeChange" v-model="leaveTime"
                             style="height: 30px;border-radius: 5px;border: 1px solid #ddd;text-indent:10px;">分钟后至离开状态
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div style="height:100%;" v-show="activeIndex == 4">
              <div class="cur_version" v-if="!showHistoryVersion">
                <div class="version_detail">
                  <div class="versiontitle">
                    <div class="num">当前版本：<span>{{ vs }}</span></div>
                    <div class="date" v-if="curVersionDetail">更新日期：
                      <span>{{ curVersionDetail.UpdateTime.substring(0, 10) }}
                        {{ curVersionDetail.UpdateTime.substring(11, 16) }}</span>
<!--                      <span>{{ versionUpdateTime.substring(0, 10) }}-->
<!--                        {{ versionUpdateTime.substring(11, 16) }}</span>-->
                    </div>
                  </div>
                  <div class="download_btn">
                    <!-- <div class="down_btn" :class="{'aciveBtn':activeBtn == 0}" @mousedown.stop="heightLight(0)" @click.stop="downloadPlug()" @mouseup.stop="heightLight(0)">插件下载</div> -->
                    <div class="down_btn" :class="{ 'aciveBtn': activeBtn == 1 }" @mousedown.stop="heightLight(1)"
                         @click.stop="open()" @mouseup.stop="heightLight(0)">检查更新</div>
                    <div class="down_btn" :class="{ 'aciveBtn': activeBtn == 2 }" @mousedown.stop="heightLight(2)"
                         @click.stop="downloadPc" @mouseup.stop="heightLight(0)">Windows版本下载</div>
                    <div class="down_btn" :class="{ 'aciveBtn': activeBtn == 3 }" @mousedown.stop="heightLight(3)"
                         @mouseup.stop="heightLight(0)">
                      <span>安卓版本下载</span>
                      <div class="qr_code">
                        <div class="img">
                          <qriously value="http://222.79.63.199:30030/versionManage/download/IM.apk" :size="112" />
                        </div>
                        <p>手机扫一扫下载</p>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="consturctor" v-if="curVersionDetail">
                  <div class="consturctor_item">
                    <div class="consturctorname" style="background-color:#defbde;color:#24b324;"
                         v-if="optimizationShow">优化</div>
                    <ol class="olitem">
                      <li v-for="(item, index) in curVersionDetail.NTalkVersionDetailList" v-if="item.Type == '优化'">
                        <span>{{ item.Des }}</span>
                      </li>
                    </ol>
                  </div>
                  <div class="consturctor_item">
                    <div class="consturctorname" style="background-color:#e6edfa;color:#4c8eff;" v-if="addShow">新增</div>
                    <ol class="olitem">
                      <li v-for="(item, index) in curVersionDetail.NTalkVersionDetailList" v-if="item.Type == '新增'">
                        <span>{{ item.Des }}</span>
                      </li>
                    </ol>
                  </div>
                  <div class="consturctor_item">
                    <div class="consturctorname" style="background-color:#faebda;color:#fa7500;" v-if="repairShow">修复
                    </div>
                    <ol class="olitem">
                      <li v-for="(item, index) in curVersionDetail.NTalkVersionDetailList" v-if="item.Type == '修复'">
                        <span>{{ item.Des }}</span>
                      </li>
                    </ol>
                  </div>
                </div>
                <div class="Nullconsturctor" v-else> <span>暂无版本信息</span></div>
                <div class="toHistoryVersion" @click.stop="showVersionDetail">历史版本<img
                  src="static\image\home\month_next.png" /></div>
              </div>
              <div class="history_version" v-else>
                <div class="toHistoryVersion">
                  <div class="back" @click.stop="backCurrent">
                    <img src="static\image\home\month_last.png" />返回
                  </div>
                  <div class="time">
                    <div class="timeArea">
                      <img src="static\image\home\schedule_time.png" />
                      <span style="padding:0 6px;" v-if="timeArea">{{ timeArea? `${$formatDateTime(timeArea[0],
                        true)}至${$formatDateTime(timeArea[1], true)}` : ""
                        }}</span>
                      <div class="timeshow">
                        <el-date-picker class="date_picker_box" align="right" v-model="timeArea" type="daterange"
                                        start-placeholder="开始日期" end-placeholder="结束日期" @change="setTime(1)">
                        </el-date-picker>
                      </div>
                    </div>
                    <img class="delete" @click.stop="setTime(0)" v-if="timeArea"
                         src="static\image\home\record_time_del.png" alt="">
                  </div>
                </div>
                <div class="historeVersionDetail" v-if="historeVersions">
                  <div class="hs_v" v-for="(item, index) in historeVersions">
                    <div class="version_title">
                      <div class="left">
                        <div class="orange"></div>
                        <div class="ver_num">V{{ item.Version }}</div>
                      </div>
                      <div class="date">更新日期：
                        <span>{{ item.UpdateTime.substring(0, 10) }} {{ item.UpdateTime.substring(11, 16) }}</span>
                      </div>
                    </div>
                    <ul class="detaillist">
                      <li class="vs_detail" v-for="(content, ids) in item.NTalkVersionDetailList">
                        <span>{{ content.Type + "：" }}</span>
                        <p style="display:inline-block;flex:1;">{{ content.Des }}</p>
                      </li>
                    </ul>
                  </div>
                </div>
              </div>
            </div>
            <div class="data_merge" v-show="activeIndex == 5">
              <div class="data_head">
                <div class="data_directory">数据目录</div>
                <div class="data_content" @click="openDataPath" ref="dataPath">{{ dataPath }}</div>
                <img ref="refresh" src="static/image/home/updateExe/refresh.png" class="refresh"
                     @click.stop.prevent="getDatePaths" />
                <el-tooltip effect="dark" placement="bottom">
                  <div slot="content">
                    第一步：打开旧的客户端文件目录，选择复制(UserFiles\用户id)目录下的数据库(*.db)<br />
                    第二步：将旧的数据库拷贝到新的客户端文件目录的(UserFiles\用户id)文件夹下<br />
                    第三步：点击刷新按钮，选择需要合并的数据库，点击合并数据按钮
                  </div>
                  <img src="static/image/home/updateExe/tips.png" class="tips" @click.stop.prevent="showTips" />
                </el-tooltip>
              </div>
              <div class="data_body">
                <el-table ref="multipleTable" @selection-change="changeData" height="320" size="small" :data="data"
                          :header-cell-style="{ background: '#f5f5f5' }" style="width: 100%;">
                  <el-table-column type="selection" width="80">
                  </el-table-column>
                  <el-table-column prop="name" label="文件名">
                  </el-table-column>
                </el-table>
              </div>
              <div class="data_foot">
                <div>已选:{{ selectDataNum }}个文件</div>
                <div class="foot-button">
                  <div class="foot-button-text" @click.stop.prevent="pooledData">{{ "合并数据" }}</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <el-card class="box-card" v-if="isShowNewV">
        <div slot="header" class="clearfix">
          <span>提示</span>
          <el-button style="float: right; padding: 3px 0;color:#999999" type="text" icon="el-icon-close"
                     @click.stop.prevent="isShowNewV = false"></el-button>
        </div>
        <div class="text item">
          <div>检测到最新版本V{{ this.newVersion }}</div>
          <div class="consturctor">
            <div class="consturctor_item consturctor_item1">
              <div class="consturctorname" style="background-color:#defbde;color:#24b324;width:25px">优化</div>
              <ol class="olitem olitems">
                <li clss="disc1" v-for="(item, index) in newVersionDetail.NTalkVersionDetailList" :key="index"
                    v-if="item.Type == '优化'">{{ item.Des }}</li>
              </ol>
            </div>
            <div class="consturctor_item consturctor_item1">
              <div class="consturctorname" style="background-color:#e6edfa;color:#4c8eff;width:25px">新增</div>
              <ol class="olitem olitems">
                <li clss="disc1" v-for="(item, index) in newVersionDetail.NTalkVersionDetailList" :key="index"
                    v-if="item.Type == '新增'">{{ item.Des }}</li>
              </ol>
            </div>
            <div class="consturctor_item consturctor_item1">
              <div class="consturctorname" style="background-color:#faebda;color:#fa7500;width:25px">修复</div>
              <ol class="olitem olitems">
                <li clss="disc1" v-for="(item, index) in newVersionDetail.NTalkVersionDetailList" :key="index"
                    v-if="item.Type == '修复'">{{ item.Des }}</li>
              </ol>
            </div>
          </div>
        </div>
        <div>
          <div class="box-bottom">
            <div class="system_list_wrap_alert_u_c_n">
              <div @click.stop.prevent="upDateNew">{{ "立即更新" }}</div>
            </div>
            <div class="system_list_wrap_alert_u_c_n system_list_wrap_alert_u_c_n_color">
              <div @click.stop.prevent="isShowNewV = false">{{ "下次再说" }}</div>
            </div>
          </div>
        </div>
      </el-card>
      <el-dialog title="数据合并" top="25vh" width="40%" :visible.sync="isShowBar" :modal-append-to-body="false"
                 :show-close="false" :close-on-click-modal="false">
        <el-progress type="circle" :percentage="upPercentage" :stroke-width="10" color="#fa7500"></el-progress>
        <div style="margin-top:20px">{{ uploadDataNum }}/{{ dataTotal }}条</div>
        <div>数据正在合并中请耐心等待...</div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { release } from "os";
export default {
  name: "system-item",
  props: {
    messageTipsArr: {}
  },
  data() {
    return {
      vs: '',
      statciVersionArray: null, //zk128新增,获取到历史版本的原始值，用来做筛选
      historeVersions: null, //zk128新增，历史版本信息
      curVersionDetail: null, //zk当前版本信息
      versionUpdateTime: '', //更新时间
      timeArea: null, //zk128新增，版本信息时区
      activeBtn: -1, //zk127新增，激活的是哪个
      showHistoryVersion: false, //zk126新增，显示当前版本还是历史版本
      activeIndex: 0,
      menuList: [
        "通知",
        "快捷键",
        "文件管理",
        "个人设置",
        "版本信息",
        "数据合并",
      ],
      autoStart: true, //开机启动状态
      send: "1", //发送消息快捷键
      activation: "Ctrl+W", //激活窗口快捷键
      session: "Alt+R", //跳转未读会话快捷键
      screen: "Ctrl+A", //截图快捷键
      search: "Alt+Q", //搜索快捷键
      newMessage: true, //新消息通知状态
      voicePrompt: false, //声音提示状态
      deskNotic: true, //桌面通知状态
      minimized: true,
      isLeave: false, //设置离开
      leaveTime: 5, //离开时间
      conversation: 20, //会话显示上限
      bootlogin: false,
      noticList: ["接收新消息通知", "消息提示音", "桌面通知"],
      rTime: 0,
      pathValue: "",
      newVersion: "",
      newVersionDetail: "",
      isShowNewV: false,
      data: [],
      selectDataNum: 0,
      dataPath: "",
      isShowBar: false,
      dataTotal: 0,
      uploadDataNum: 0,
      upPercentage: 0,
      num: 1,
      optimizationShow: false, //优化标题显示状态
      repairShow: false, //修复标题显示状态
      addShow: false, //新增标题显示状态
    };
  },
  computed: {
    ...mapState(["Version"]),
    hot() {
      return this.$store.state.user_hot_key;
    },
    myId() {
      return this.$store.state.myInfo.id;
    },
  },
  methods: {
    //展示右下角消息闪烁，新
    showTips() {
      // unNoticeArr
      let arry = [];
      if (this.messageTipsArr) {
        for (let i in this.messageTipsArr) {
          arry.push(this.messageTipsArr[i][this.messageTipsArr[i].length - 1]);
        }
      }
      console.log("拿到闪烁消息", arry, this.messageTipsArr);
      let res = this.$shell("GetNewInfo_New", [arry, "getNewInfo"]);
    },
    openDataPath() {
      let res = this.$shell("OpenPathByUrl", [this.dataPath, ""]);
    },
    SetMergeSqliterCount(isSuccess, msg, num) {
      if (isSuccess == "false") {
        return this.$confirm("合并出现错误!", "提示", {
          showCancelButton: false,
          confirmButtonText: "确定",
          type: "error",
        }).then(() => {
          this.isShowBar = false;
        });
      }
      this.uploadDataNum = Number(num);
      this.upPercentage = Math.floor(
        (this.uploadDataNum / this.dataTotal) * 100
      );
      if (this.uploadDataNum >= this.dataTotal) {
        this.isShowBar = false;
        return this.$confirm("数据合并成功", "提示", {
          showCancelButton: false,
          confirmButtonText: "确定",
          type: "success",
        }).then(() => {
          this.isShowBar = false;
          this.$emit("getSessionList");
        });
      }
    },
    pooledData() {
      if (this.$refs.multipleTable.selection.length == 0) {
        return this.$Message.warning("未选中数据");
      }
      let upData = [];
      this.$refs.multipleTable.selection.forEach((element) => {
        upData.push(element.name);
      });
      let upDataStr = JSON.stringify(upData);
      let info = this.$shell("GetNeedMergeData", [upDataStr]);
      info = JSON.parse(info);
      if (!info.return_code) {
        return this.$Message.warning(info.return_msg);
      }
      if (info.return_msg == 0) {
        return this.$confirm("没有需要合并的数据", "提示", {
          showCancelButton: false,
          confirmButtonText: "确定",
          type: "warning",
        });
      }
      this.$confirm(
        `发现${info.return_msg}条记录要进行合并，是否继续?`,
        "提示",
        {
          cancelButtonText: "取消",
          confirmButtonText: "继续",
          type: "info",
        }
      ).then(() => {
        this.dataTotal = Number(info.return_msg);
        this.isShowBar = true;
        this.$shell("MergeSqliter_New", [upDataStr]);
      });
    },
    changeMenu(index) {
      this.activeIndex = index;
      if (index == 4) {
        let version = this.Version.substr(1);
        console.log(version);
        this.getInfoByVersion(version);
        return;
      }
      if (index == 5) {
        this.getDatePath();
      }
    },
    getDatePaths() {
      this.$refs.refresh.style = `transform:rotate(${this.num * 360}deg)`;
      this.num++;
      this.getDatePath();
    },
    getDatePath() {
      let dataInfo = this.$shell("GetCanMergeSqliter", []);
      dataInfo = JSON.parse(dataInfo);
      this.dataPath = dataInfo.path;
      let dbs = JSON.parse(dataInfo.dbs);
      this.data = [];
      for (let i in dbs) {
        this.data.push({ name: dbs[i] });
      }
    },
    changeData(val) {
      this.selectDataNum = val.length;
      console.log(val, "选中的数据");
    },
    upDateNew() {
      //  2023 01 30  注释
      // this.$shell("ManualUpdate", ["1"]);
      // this.$message({
      //   type: "success",
      //   message: "后台开始下载，升级中!",
      // });
      // this.isShowNewV = false;

      // 2023 01 30   新增
      return this.$shell("ClientUpdate", []);
    },

    //新增插件下载
    downloadPlug() {
      let res = this.$downloadPlug(
        "PluginUpdateAndDownload",
        "UMP_Plugin_Proxy"
      );
      console.log(res, 428);
    },
    open() {
      let info = this.$shell("ManualUpdate", ["0"]);
      let infoNew = this.$shell("GetNewestVersion", []);
      // if (!infoNew.V1 || !infoNew.V2) {
      //   return this.$message({
      //     message: "系统正在升级,请稍后再试",
      //     type: "error",
      //   });
      // }

      console.log(info, "==>手动升级system");
      if (infoNew.Return_code) {
        this.newVersionDetail = JSON.parse(infoNew.V2);
        this.newVersion = JSON.parse(infoNew.V2).Version;  //  2023 01 30  V1 改 V2
      }
      console.log(infoNew, "==>最新版本");
      //  2023.1.30  info 改为 infoNew
      if (infoNew.Return_code) {
        if (infoNew.V3 == 'False') {
          this.$message({
            message: "已经是最新版本",
            type: "success",
          });
          // this.$shell("ClientUpdate", []);  // 0628 注释
          return;
        }
        this.isShowNewV = true;

        // return this.$shell("ClientUpdate", []); //  0628  新增  // 2023 01 30  注释


        // //console.log(this.$shell("ManualUpdate",['1']))

        // 0628  注释
        // if (this.$shell("ManualUpdate", ["1"]).IsDownload) {
        //   this.$message({
        //     message: "后台下载中",
        //     type: "warning",
        //   });
        //   return;
        // }
      }


      //   this.$confirm(`最新版本为V${this.newVersion},是否升级？`, "提示", {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //     type: "warning",
      //   })
      //     .then(() => {
      //       this.$shell("ManualUpdate", ["1"]);
      //       this.$message({
      //         type: "success",
      //         message: "后台开始下载，升级中!",
      //       });
      //     })
      //     .catch(() => {
      //       this.$message({
      //         type: "info",
      //         message: "已取消",
      //       });
      //     });
    },
    updateCheck() {
      let info = this.$shell("ManualUpdate", ["0"]);
      if (info.Return_code) {
        this.$shell("ManualUpdate", ["1"]);
        console.log("1234", this.$shell("ManualUpdate", ["1"]));
        // if(!info.IsNeedUpdate){
        //   alert('已经是最新版本')
        //   return
        // }
      }
    },
    downloadPc() {
      //pc版下载
      let isWin7=localStorage.getItem('isWin7');
      console.log(isWin7,'是否win7');
      //旧
      //location.href =isWin7=='true'?'http://222.79.63.199:30030/versionManage/download/IM_PC_WIN7.exe':'http://222.79.63.199:30030/versionManage/download/IM_PC.exe';
      //新
      location.href =isWin7=='true'?'http://222.79.63.199:30030/versionManage/download/IM_PC_WIN7_new.exe':'http://222.79.63.199:30030/versionManage/download/IM_PC_new.exe';
    },
    getInfoByVersion(str) {
      //zk128新增，根据版本号获取版本信息
      let info = this.$shell("GetVersion", [str]);
      let infoNew = this.$shell("GetNewestVersion", []);
      console.log(infoNew, info, str, "infoNew");
      let _this = this;
      if (infoNew.Return_code) {
        this.curVersionDetail = JSON.parse(infoNew.V1);
        //this.versionUpdateTime = JSON.parse(infoNew.V2).UpdateFiles[0].FileUpdateTime
        //  2023 01 30  版本号替换为动态
        this.vs = JSON.parse(infoNew.V1).Version
        // 判断各标题下是否有内容，无则不显示标题
        this.curVersionDetail.NTalkVersionDetailList.forEach((item) => {
          if (item.Type == "优化") {
            _this.optimizationShow = true;
          }
          if (item.Type == "修复") {
            _this.repairShow = true;
          }
          if (item.Type == "新增") {
            _this.addShow = true;
          }
        });
      }
      if (infoNew.Return_code) {
        this.newVersion = JSON.parse(infoNew.V2).Version;
      }
      console.log(info, infoNew, str, "版本信息");
    },
    setTime(index) {
      //zk128新增
      let arr = this.statciVersionArray;
      let starstime = null;
      let endtime = null;
      if (index == 0) {
        //清除时间
        this.timeArea = null;
      } else {
        starstime = new Date(this.timeArea[0]);
        endtime = new Date(this.timeArea[1]);
      }
      if (this.timeArea) {
        arr = arr.filter((item) => {
          let time = new Date(item.UpdateTime);
          return time >= starstime && time <= endtime;
        });
      }
      this.historeVersions = [...arr];
    },
    heightLight(index) {
      //zk127按钮切换高亮
      this.activeBtn = index;
    },
    showVersionDetail() {
      //zk127
      this.showHistoryVersion = true;
      // let info = this.$shell("GetNewestVersion",[])
      // console.log(info,"最新版本")
      // let info1 = this.$shell("GetVersion",["1.2.0.5"])
      // console.log(info1,"1.2.05版本")
      // let info2 = this.$shell("GetHistoryVersion",[])
      // console.log(info2,"历史版本")
      let info = this.$shell("GetHistoryVersion", []);
      console.log(info, "历史版本信息");
      this.statciVersionArray = JSON.parse(info.V1);
      this.historeVersions = JSON.parse(info.V1);
    },
    backCurrent() {
      this.showHistoryVersion = false;
    },
    bootloginChange() {
      this.$nextTick(() => {
        let req = this.$shell("AutoStartUp", [
          this.bootlogin ? "TRUE" : "FALSE",
        ]);
        req = JSON.parse(req);
        if (req.return_code == "TRUE") {
          var rep = this.operationalDatabase(
            `UPDATE system_${this.myId} SET bootlogin='${this.bootlogin}' WHERE id='${this.myId}';`
          );
          console.log(rep, "开机启动设置成功");
          this.$store.state.user_configure[0].bootlogin = this.bootlogin
            ? "true"
            : "false";
        } else {
          this.bootlogin = !this.bootlogin;
          this.$Message.warning("设置开机启动失败");
          this.$store.state.user_configure[0].bootlogin = this.bootlogin
            ? "true"
            : "false";
        }
      });
    },
    leaveTimeChange() {
      this.$nextTick(() => {
        if (!this.leaveTime || this.leaveTime <= 1) {
          this.leaveTime = 1;
        }
        var rep = this.operationalDatabase(
          `UPDATE system_${this.myId} SET leaveTime='${this.leaveTime}' WHERE id='${this.myId}';`
        );
        if (rep.success === "true") {
          this.$store.state.user_configure[0].leaveTime = this.leaveTime;
          // 新增判断电脑是否操作
          let info = this.$shell("AutoLever", [
            this.$store.state.user_configure[0].isLeave,
            parseInt(this.$store.state.user_configure[0].leaveTime),
          ]);
        }
        console.log(rep);
      });
    },
    conversationChange() {
      this.$nextTick(() => {
        if (this.conversation <= 15) {
          this.conversation = 15;
        } else {
          this.conversation = parseInt(this.conversation);
        }
        var rep = this.operationalDatabase(
          `UPDATE system_${this.myId} SET conversation='${this.conversation}' WHERE id='${this.myId}';`
        );
        if (rep.success === "true") {
          this.$store.state.user_configure[0].conversation = this.conversation;
        }
        console.log(rep);
      });
    },
    statusChange() {
      this.$nextTick(() => {
        console.log(this.newMessage);
        var rep = this.operationalDatabase(
          `UPDATE system_${this.myId} SET isLeave='${this.isLeave}' WHERE id='${this.myId}';`
        );
        if (rep.success === "true") {
          this.$store.state.user_configure[0].isLeave = this.isLeave
            ? "true"
            : "false";
          // 新增判断电脑是否操作
          let info = this.$shell("AutoLever", [
            this.$store.state.user_configure[0].isLeave,
            parseInt(this.$store.state.user_configure[0].leaveTime),
          ]);
        }
        console.log(rep);
      });
    },
    openPathByUrl() {
      console.log(this.pathValue, "pathValue");
      let res = this.$shell("OpenPathByUrl", [this.pathValue, ""]);
      console.log(res, "openPathByUrl");
    },
    editPath() {
      let res = this.$shell("GetLocalFilePath", []);
      res = res.replace(/\\/g, "\\\\");
      console.log(res, "path");
      res = JSON.parse(res);
      if (res.return_code == "TRUE") {
        console.log(res, "path");
        this.pathValue = res.return_msg;
        this.update_hot_user(5, res.return_msg);
        let file = this.operationalDatabase(
          `UPDATE user_hot_key SET path='${this.pathValue}' WHERE id='${this.myId}';`
        );
        console.log(file, "fileconsole");
        let user_hot = this.operationalDatabase(
          `SELECT * FROM user_hot_key WHERE id='${this.myId}';`,
          1
        );
        console.log(user_hot, "user_hot");
      }
    },
    sendSet(e) {
      console.log(e, this.send, "切换快捷键");
      // if(e.target.value){
      let req = this.operationalDatabase(
        `UPDATE user_hot_key SET send='${this.send}' WHERE id='${this.myId}';`
      );
      this.update_hot_user(4, this.send);
      this.$emit("setSendHot", this.send);
      // this.$store.commit('set_user_hot_key',{index:4,key:this.send});
      // console.log(this.$store.state.user_hot_key,'user_hot_key');
      // let user_hot = this.operationalDatabase(`SELECT * FROM user_hot_key WHERE id='${this.myId}';`, 1);
      // console.log(user_hot);
      // if(user_hot.success=="true"){
      // 	let res = user_hot.list[0]?user_hot.list[0]:[];
      // 	console.log(res,'ressend');
      // 	this.$store.commit('set_user_hot_key',[]);
      // 	this.$store.commit('set_user_hot_key',[res.search, res.screen, res.session, res.window, res.send,res.path]);
      // 	console.log(this.$store.state.user_hot_key,'user_hot_key111');
      // 		// this.$store.state.user_hot_key=[];
      // 	this.$forceUpdate();
      // }
      // }
    },
    messageClick() {
      this.$nextTick(() => {
        console.log(this.newMessage);
        var rep = this.operationalDatabase(
          `UPDATE system_${this.myId} SET notify='${this.newMessage}' WHERE id='${this.myId}';`
        );
        if (rep.success === "true") {
          this.$store.state.user_configure[0].notify = this.newMessage
            ? "true"
            : "false";
        }
        console.log(rep);
      });
    },
    voiceClick() {
      this.$nextTick(() => {
        console.log(this.voicePrompt);
        var rep = this.operationalDatabase(
          `UPDATE system_${this.myId} SET warningTone='${this.voicePrompt}' WHERE id='${this.myId}';`
        );
        if (rep.success === "true") {
          this.$store.state.user_configure[0].warningTone = this.voicePrompt
            ? "true"
            : "false";
        }
        console.log(rep);
      });
    },
    noticClick() {
      this.$nextTick(() => {
        console.log(this.session);
        var rep = this.operationalDatabase(
          `UPDATE system_${this.myId} SET notice='${this.deskNotic}' WHERE id='${this.myId}';`
        );
        if (rep.success === "true") {
          this.$store.state.user_configure[0].notice = this.deskNotic
            ? "true"
            : "false";
        }
        if (this.deskNotic) {
          console.log(this.messageTipsArr,797);
          this.showTips()
        }
        console.log(rep);
      });
    },
    minimizedClick() {
      this.$nextTick(() => {
        console.log(this.minimized);
        if (this.minimized) {
          let rep = this.$shell("MinimizeToPalletArea", ["0"]);
        } else {
          let rep = this.$shell("MinimizeToPalletArea", ["1"]);
        }
        var xx = this.operationalDatabase(
          `UPDATE system_${this.myId} SET minimized='${this.minimized}' WHERE id='${this.myId}';`
        );
        console.log(xx);
      });
    },
    close() {
      this.$emit("setClose", 2);
    },
    searchKeydown(e) {
      this.search = "";
      this.search = this.$keyCodeName(e);
      console.log(this.search, "按下的按键");
    },
    update_hot_user(index, value) {
      this.$store.state.user_hot_key[index] = value;
    },
    operationalDatabase(statements, index) {
      let to = JSON.stringify({
        Sqlstr: statements,
      });
      return arguments[1]
        ? JSON.parse(this.$shellSQL(to, index))
        : JSON.parse(this.$shellSQL(to));
    },
    keyIsRepeat(key) {
      console.log(this.hot, key, "key111");
      for (let i = 0; i < this.hot.length; i++) {
        if (this.hot[i] == key) {
          return true;
        }
      }
      return false;
    },
    searchUp(e) {
      if (this.rTime == 0) {
        if (this.keyIsRepeat(this.search)) {
          console.log("热键重置");
          this.$Message.warning("热键重复,请重新设置");
          this.search = this.hot[0];
          return;
        }
        this.rTime = new Date().getTime();
        let dds = this.$shell("HotKeyUnRegist", ["0"]);
        console.log("unregist result is ------------->");
        console.log(dds);
        let rep = this.$shell("HotKeyRegister", [
          "0",
          "TRUE",
          this.search,
          "jumpSearch",
        ]);
        rep = JSON.parse(rep);
        console.log(rep, "rep");
        if (rep.return_code == "TRUE") {
          let sc = this.operationalDatabase(
            `SELECT * FROM user_hot_key WHERE id='${this.myId}';`,
            1
          );
          console.log("sc", sc);
          let res = this.operationalDatabase(
            `UPDATE user_hot_key SET search='${this.search}' WHERE id='${this.myId}';`
          );
          this.update_hot_user(0, this.search);
          this.$Message.success("热键注册成功");
        } else {
          this.search = this.hot[0];
          this.$shell("HotKeyRegister", [
            "0",
            "TRUE",
            this.search,
            "jumpSearch",
          ]);
          this.$Message.warning(rep.return_msg);
        }
        setTimeout(() => {
          this.rTime = 0;
        }, 300);
      }
    },
    screenKeydown(e) {
      this.screen = "";
      this.screen = this.$keyCodeName(e);
    },
    screenUp(e) {
      if (this.rTime == 0) {
        if (this.keyIsRepeat(this.screen)) {
          console.log("热键重置");
          this.$Message.warning("热键重复,请重新设置");
          this.screen = this.hot[1];
          return;
        }
        this.rTime = new Date().getTime();
        let dds = this.$shell("HotKeyUnRegist", ["1"]);
        let rep = this.$shell("HotKeyRegister", [
          "1",
          "TRUE",
          this.screen,
          "emithot",
        ]);
        rep = JSON.parse(rep);
        if (rep.return_code == "TRUE") {
          console.log(this.screen, "screen");
          let res = this.operationalDatabase(
            `UPDATE user_hot_key SET screen='${this.screen}' WHERE id='${this.myId}';`
          );
          this.update_hot_user(1, this.screen);
          this.$Message.success("热键注册成功");
        } else {
          this.screen = this.hot[1];
          this.$shell("HotKeyRegister", ["1", "TRUE", this.screen, "emithot"]);
          this.$Message.warning(rep.return_msg);
        }
        setTimeout(() => {
          this.rTime = 0;
        }, 300);
      }
    },
    sessionKeydown(e) {
      this.session = "";
      this.session = this.$keyCodeName(e);
    },
    sessionUp(e) {
      if (this.rTime == 0) {
        if (this.keyIsRepeat(this.session)) {
          console.log("热键重置");
          this.$Message.warning("热键重复,请重新设置");
          this.session = this.hot[2];
          return;
        }
        this.rTime = new Date().getTime();
        let dds = this.$shell("HotKeyUnRegist", ["2"]);
        let rep = this.$shell("HotKeyRegister", [
          "2",
          "TRUE",
          this.session,
          "jumpUnread",
        ]);
        rep = JSON.parse(rep);
        console.log(rep, "rep");
        if (rep.return_code == "TRUE") {
          let res = this.operationalDatabase(
            `UPDATE user_hot_key SET session='${this.session}' WHERE id='${this.myId}';`
          );
          this.update_hot_user(2, this.screen);
          this.$Message.success("热键注册成功");
        } else {
          this.session = this.hot[2];
          this.$shell("HotKeyRegister", [
            "2",
            "TRUE",
            this.session,
            "jumpUnread",
          ]);
          this.$Message.warning(rep.return_msg);
        }
        setTimeout(() => {
          this.rTime = 0;
        }, 300);
      }
    },
    activationKeydown(e) {
      this.activation = "";
      this.activation = this.$keyCodeName(e);
    },
    activationUp(e) {
      if (this.rTime == 0) {
        if (this.keyIsRepeat(this.activation)) {
          console.log("热键重置");
          this.$Message.warning("热键重复,请重新设置");
          this.activation = this.hot[3];
          return;
        }
        this.rTime = new Date().getTime();
        let dds = this.$shell("HotKeyUnRegist", ["3"]);
        let rep = this.$shell("HotKeyRegister", [
          "3",
          "TRUE",
          this.activation,
          "ActivateMainForm",
        ]);
        rep = JSON.parse(rep);
        console.log(rep, "rep");
        if (rep.return_code == "TRUE") {
          let res = this.operationalDatabase(
            `UPDATE user_hot_key SET window='${this.activation}' WHERE id='${this.myId}';`
          );
          this.update_hot_user(3, this.activation);
          this.$Message.success("热键注册成功");
        } else {
          this.activation = this.hot[3];
          this.$shell("HotKeyRegister", [
            "3",
            "TRUE",
            this.activation,
            "ActivateMainForm",
          ]);
          this.$Message.warning(rep.return_msg);
        }
        setTimeout(() => {
          this.rTime = 0;
        }, 300);
      }
    },
    operationalDatabase(statements, index) {
      let to = JSON.stringify({
        Sqlstr: statements,
      });
      return arguments[1]
        ? JSON.parse(this.$shellSQL(to, index))
        : JSON.parse(this.$shellSQL(to));
    },
    testSystem() {
      //				var xx=this.operationalDatabase(
      //					`REPLACE INTO system_${this.myId}(notify,warningTone,notice,id) VALUES('false','false','false','${this.myId}');`
      //				)
      //				console.log(xx,'xx')
      var data = this.operationalDatabase(
        `SELECT * FROM system_${this.myId};`,
        1
      );
      if (data.list.length) {
        if (data.list[0].notice === "true" || data.list[0].notice == "") {
          this.deskNotic = true;
        } else {
          this.deskNotic = false;
        }
        if (data.list[0].notify === "true" || data.list[0].notify == "") {
          this.newMessage = true;
        } else {
          this.newMessage = false;
        }
        if (data.list[0].warningTone === "true") {
          this.voicePrompt = true;
        } else {
          this.voicePrompt = false;
        }
        if (data.list[0].minimized === "true") {
          this.minimized = true;
        } else {
          this.minimized = false;
        }
        if (data.list[0].isLeave === "true") {
          this.isLeave = true;
        } else {
          this.isLeave = false;
        }
        if (data.list[0].leaveTime) {
          this.leaveTime = data.list[0].leaveTime || 5;
        }
        if (data.list[0].conversation) {
          this.conversation = data.list[0].conversation || 15;
        }
        if (data.list[0].bootlogin == "true") {
          this.bootlogin = true;
        } else {
          this.bootlogin = false;
        }
      } else {
        var xx = this.operationalDatabase(
          `REPLACE INTO system_${this.myId}(notify,warningTone,notice,id,minimized) VALUES('true','false','true','${this.myId}','true');`
        );
      }
    },
    getDefaultPath() {
      let res = this.$shell("GetDefultLoacalPath", [this.myId]);
      res = res.replace(/\\/g, "\\\\");
      console.log(res, "path");
      res = JSON.parse(res);
      console.log(res, "path1");
      // res=eval('(' + res + ')');
      // console.log(res,'path')
      if (res.return_code == "TRUE") {
        console.log(res, "path");
        this.pathValue = res.return_msg;
        let file = this.operationalDatabase(
          `UPDATE user_hot_key SET path='${res.return_msg}' WHERE id='${this.myId}';`
        );
        console.log(file, "fileconsole");
        let user_hot = this.operationalDatabase(
          `SELECT * FROM user_hot_key WHERE id='${this.myId}';`,
          1
        );
        console.log(user_hot, "user_hot");
      }
    },

    //下载插件   xsz 新增
    downloadProcess(msg) {
      console.log(msg, "下载进度");
    },
    decompressionFile(msg) {
      console.log(msg, "解压");
    },
  },
  created() {
    // this.getDefaultPath();
    this.testSystem();
    let res = this.$shell("GetHotKey", []);
    this.search = this.hot[0];
    this.screen = this.hot[1];
    this.session = this.hot[2];
    this.activation = this.hot[3];
    this.send = this.hot[4];
    this.pathValue = this.hot[5];
    // == "1" ? "Enter发送" : "Ctrl+Enter发送"
    // zk128新增，获取当前版本的信息
    window.SetMergeSqliterCount = this.SetMergeSqliterCount;

    /* 新增插件下载  */
    window.downloadProcess = this.downloadProcess;
    window.decompressionFile = this.decompressionFile;

  },
};
</script>
<style scoped lang="less">
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  width: 340px;
  position: absolute;
  top: 9em;
  height: 300px;
  margin: auto;
  left: 15em;
}

.box-card /deep/ .el-card__header {
  padding: 6px 20px;
  text-align: left;
  font-size: 14px;
  font-weight: normal;
  font-stretch: normal;
  letter-spacing: 0px;
  color: #333333;
}

.box-card /deep/ .el-card__body {
  padding: 0px 0px;
}

.text {
  text-align: left;
  font-size: 14px;
  font-weight: normal;
  font-stretch: normal;
  letter-spacing: 0px;
  color: #333333;
  height: 200px;
  overflow: auto;
  padding: 5px 20px;
}

.box-bottom {
  display: flex;
  position: absolute;
  bottom: 10px;
  width: 330px;
  justify-content: flex-end;
}

.system_list_wrap_alert_u_c_n {
  width: 80px;
  height: 28px;
  font-size: 12px;
  color: #fff;
  border-radius: 4px;
  background: #fa7500;
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 10px;
}

.system_list_wrap_alert_u_c_n_color {
  background: #fff;
  border: solid 1px #d9d9d9;
  color: #333333;
}

.consturctor_item1 {
  padding: 10px 0;
  font-size: 11px;
}

.olitems {
  padding: 0 20px;
}

.olitems li {
  list-style: disc !important;
  padding: 2px 0px;
}

.data_merge {
  text-align: left;
  padding: 20px;

  .data_head {
    display: flex;

    .data_directory {
      font-size: 14px;
      font-weight: normal;
      font-stretch: normal;
      letter-spacing: 0px;
      color: #333333;
      padding: 0 10px;
    }

    .data_content {
      padding: 0 2px;
      border-bottom: 1px solid #e6e6e6;
      height: 23px;
      width: 350px;
      cursor: pointer;
    }

    .data_content:hover {
      color: #fa7500;
    }

    .refresh {
      width: 14px;
      height: 14px;
      margin-left: 5px;
      margin-top: 5px;
      transition: transform 0.5s;
      cursor: pointer;
    }

    .tips {
      width: 15px;
      height: 15px;
      position: relative;
      left: 40px;
      top: -10px;
    }
  }
}

.data_body {
  padding: 25px 0;
}

.data_body /deep/.el-table-column--selection .cell {
  padding-left: 30px;
}

.data_foot {
  position: absolute;
  height: 40px;
  border-top: solid 1px #e6e6e6;
  width: 100%;
  bottom: 12px;
  left: 0;
  display: flex;
  justify-content: space-between;
  line-height: 50px;
  padding: 0px 20px;

  .foot-button {
    width: 100px;
    height: 30px;
    border-radius: 4px;
    border: solid 1px #fa7500;
    text-align: center;
    line-height: 30px;
    position: relative;
    top: 10px;
    cursor: pointer;

    .foot-button-text {
      font-size: 14px;
      font-weight: normal;
      font-stretch: normal;
      letter-spacing: 0px;
      color: #fa7500;
    }
  }
}
</style>
